package jp.ac.aiit.spg.service.impl;

import java.util.*;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import jp.ac.aiit.spg.common.*;
import jp.ac.aiit.spg.dao.*;
import jp.ac.aiit.spg.entity.*;
import jp.ac.aiit.spg.service.HelloService;
import jp.ac.aiit.spg.service.SpgService;
import jp.ac.aiit.spg.web.wbs.SpgTaskTemplete;

@Stateless
public class HelloServiceImpl implements HelloService {

	@EJB
	private SpgUserDao suDao;

	@EJB
	private SpgTaskDao stDao;

	@EJB
	private SpgProjectDao spDao;

	@EJB
	private SpgMemberDao smDao;

	@EJB
	private SpgWBSDao swDao;

	@EJB
	private SpgToDoDao stdDao;

	@EJB
	private SpgService spgss;

	public void create1() {

		// テスト用データ

		// プロジェクトを準備する
		spgss.createProject("PBL0704", "SPG Project - 中鉢チーム");
		SpgProject p1 = spgss.findProject("PBL0704");
		spgss.createProject("PBL0709", "PMO Project - 酒森チーム");
		SpgProject p2 = spgss.findProject("PBL0709");

		// ユーザーを準備する
		spgss.createUser("a0604ti", "伊藤 健", "takeru");
		SpgUser u1 = spgss.findUser("a0604ti");
		spgss.createUser("a0605ni", "伊藤 信明", "nobu");
		SpgUser u2 = spgss.findUser("a0605ni");
		spgss.createUser("a0622js", "篠塚 純子", "shino");
		SpgUser u3 = spgss.findUser("a0622js");
		spgss.createUser("a0633kn", "中谷 和史", "kazu");
		SpgUser u4 = spgss.findUser("a0633kn");
		spgss.createUser("a0648ky", "山内 健司", "ken");
		SpgUser u5 = spgss.findUser("a0648ky");
		spgss.createUser("a0614yo", "小沢 雄治", "yuji");
		SpgUser u10 = spgss.findUser("a0614yo");
		spgss.createUser("a0636sn", "中村 里美", "nakasato");
		SpgUser u11 = spgss.findUser("a0636sn");
		spgss.createUser("a0645km", "森山 薫", "mori");
		SpgUser u12 = spgss.findUser("a0645km");
		spgss.createUser("a0612yo", "大堀 葉子", "yoko");
		SpgUser u13 = spgss.findUser("a0612yo");
		spgss.createUser("a0625jt", "高橋 潤", "jun");
		SpgUser u14 = spgss.findUser("a0625jt");
		spgss.createUser("yc", "中鉢 欣秀", "yc");
		SpgUser u90 = spgss.findUser("yc");
		spgss.createUser("narita-masahiko", "成田 雅彦", "masahiko");
		SpgUser u91 = spgss.findUser("narita-masahiko");
		spgss.createUser("sakamori", "酒森 潔", "sakamori");
		SpgUser u92 = spgss.findUser("sakamori");
		spgss.createUser("*NOBODY", "未割り当て", "*none");
		SpgUser u99 = spgss.findUser("*NOBODY");

		// ユーザーをプロジェクトのメンバーに登録する（PBL0704)
		SpgMember m11 = spgss.addMember(p1.getId(), u1.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m12 = spgss.addMember(p1.getId(), u2.getId(),
				SpgRole.PROJECTMEMBER);
		SpgMember m13 = spgss.addMember(p1.getId(), u3.getId(),
				SpgRole.PROJECTMEMBER);
		SpgMember m14 = spgss.addMember(p1.getId(), u4.getId(),
				SpgRole.PROJECTMEMBER);
		SpgMember m15 = spgss.addMember(p1.getId(), u5.getId(),
				SpgRole.PROJECTMEMBER);
		SpgMember m101 = spgss.addMember(p1.getId(), u90.getId(),
				SpgRole.TEACHER);
		SpgMember m102 = spgss.addMember(p1.getId(), u91.getId(),
				SpgRole.TEACHER);
		SpgMember m109 = spgss.addMember(p1.getId(), u99.getId(),
				SpgRole.PROJECTMEMBER);

		// ユーザーをプロジェクトのメンバーに登録する（PBL0709)
		SpgMember m21 = spgss.addMember(p2.getId(), u10.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m22 = spgss.addMember(p2.getId(), u11.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m23 = spgss.addMember(p2.getId(), u12.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m24 = spgss.addMember(p2.getId(), u13.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m25 = spgss.addMember(p2.getId(), u14.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m29 = spgss.addMember(p2.getId(), u4.getId(),
				SpgRole.PROJECTMANAGER); // マルチプロジェクト対応の確認のため
		SpgMember m201 = spgss.addMember(p2.getId(), u92.getId(),
				SpgRole.TEACHER);
		SpgMember m202 = spgss.addMember(p2.getId(), u90.getId(),
				SpgRole.TEACHER);
		SpgMember m209 = spgss.addMember(p2.getId(), u99.getId(),
				SpgRole.PROJECTMEMBER);

		// タスクを作成する
		Date someday = new Date();

		// task L1
		SpgTaskTemplete stt1 = new SpgTaskTemplete();
		stt1.name = "L1 task one";
		stt1.workingTime = 6;
		stt1.isStartTimeSpecifyedByUser = true;
		stt1.startTimePlanned = someday;
		stt1.assignment = SpgAssignStatus.ASSIGNED;
		stt1.deliverableMemo = "";

		stt1.projectId = p1.getId();
		stt1.memberId = m11.getId();
		stt1.parentTaskId = spgss.getRootTask(p1.getId()).getId();

		spgss.createTask(stt1);
		SpgTask L1 = spgss.findTask(p1.getId(), "01");

		// task L1.1
		SpgTaskTemplete stt11 = new SpgTaskTemplete();
		stt11.name = "L2 task one";
		stt11.workingTime = 5;
		stt11.isStartTimeSpecifyedByUser = false;
		stt11.assignment = SpgAssignStatus.ACCEPTED;
		stt11.deliverableMemo = "";

		stt11.projectId = p1.getId();
		stt11.memberId = m11.getId();
		stt11.parentTaskId = L1.getId();

		spgss.createTask(stt11);
		SpgTask L1t1 = spgss.findTask(p1.getId(), "01.01");

		// task L1.2
		SpgTaskTemplete stt12 = new SpgTaskTemplete();
		stt12.name = "L2 task two";
		stt12.workingTime = 3;
		stt12.isStartTimeSpecifyedByUser = true;
		stt12.startTimePlanned = someday;
		stt12.assignment = SpgAssignStatus.CREATED;
		stt12.deliverableMemo = "";

		stt12.projectId = p1.getId();
		stt12.memberId = m12.getId();
		stt12.parentTaskId = L1.getId();
		stt12.PredecessorIds.add(L1t1.getId());
		spgss.createTask(stt12);
		SpgTask L1t2 = spgss.findTask(p1.getId(), "01.02");

		// task L1.3
		SpgTaskTemplete stt13 = new SpgTaskTemplete();
		stt13.name = "L2 task three";
		stt13.workingTime = 1;
		stt13.isStartTimeSpecifyedByUser = true;
		stt13.startTimePlanned = someday;
		stt13.assignment = SpgAssignStatus.REJECTED;
		stt13.deliverableMemo = "";

		stt13.projectId = p1.getId();
		stt13.memberId = m13.getId();
		stt13.parentTaskId = L1.getId();
		stt13.PredecessorIds.add(L1t2.getId());
		spgss.createTask(stt13);
		SpgTask L1t3 = spgss.findTask(p1.getId(), "01.03");

		// task L1.3.1
		SpgTaskTemplete stt131 = new SpgTaskTemplete();
		stt131.name = "L3 task one";
		stt131.workingTime = 1;
		stt131.isStartTimeSpecifyedByUser = true;
		stt131.startTimePlanned = someday;
		stt131.assignment = SpgAssignStatus.REJECTED;
		stt131.deliverableMemo = "";

		stt131.projectId = p1.getId();
		stt131.memberId = m12.getId();
		stt131.parentTaskId = L1t3.getId();
		stt131.PredecessorIds.add(L1t2.getId());
		spgss.createTask(stt131);
		SpgTask L2t1 = spgss.findTask(p1.getId(), "01.03.01");

		// task L1.3.2
		SpgTaskTemplete stt132 = new SpgTaskTemplete();
		stt132.name = "L3 task two";
		stt132.workingTime = 1;
		stt132.isStartTimeSpecifyedByUser = true;
		stt132.startTimePlanned = someday;
		stt132.assignment = SpgAssignStatus.REJECTED;
		stt132.deliverableMemo = "";

		stt132.projectId = p1.getId();
		stt132.memberId = m12.getId();
		stt132.parentTaskId = L1t3.getId();
		stt132.PredecessorIds.add(L2t1.getId());
		spgss.createTask(stt132);
		SpgTask L2t2 = spgss.findTask(p1.getId(), "01.03.02");

	}

	public void create2() {

		// デモ用データ
		
		// プロジェクトを準備する
		spgss.createProject("PBL0704", "SPG Project - 中鉢チーム");
		SpgProject p1 = spgss.findProject("PBL0704");
		spgss.createProject("PBL0709", "PMO Project - 酒森チーム");
		SpgProject p2 = spgss.findProject("PBL0709");

		// ユーザーを準備する
		spgss.createUser("a0604ti", "伊藤 健", "takeru");
		SpgUser u1 = spgss.findUser("a0604ti");
		spgss.createUser("a0605ni", "伊藤 信明", "nobu");
		SpgUser u2 = spgss.findUser("a0605ni");
		spgss.createUser("a0622js", "篠塚 純子", "shino");
		SpgUser u3 = spgss.findUser("a0622js");
		spgss.createUser("a0633kn", "中谷 和史", "kazu");
		SpgUser u4 = spgss.findUser("a0633kn");
		spgss.createUser("a0648ky", "山内 健司", "ken");
		SpgUser u5 = spgss.findUser("a0648ky");
		spgss.createUser("a0614yo", "小沢 雄治", "yuji");
		SpgUser u10 = spgss.findUser("a0614yo");
		spgss.createUser("a0636sn", "中村 里美", "nakasato");
		SpgUser u11 = spgss.findUser("a0636sn");
		spgss.createUser("a0645km", "森山 薫", "mori");
		SpgUser u12 = spgss.findUser("a0645km");
		spgss.createUser("a0612yo", "大堀 葉子", "yoko");
		SpgUser u13 = spgss.findUser("a0612yo");
		spgss.createUser("a0625jt", "高橋 潤", "jun");
		SpgUser u14 = spgss.findUser("a0625jt");
		spgss.createUser("yc", "中鉢 欣秀", "yc");
		SpgUser u90 = spgss.findUser("yc");
		spgss.createUser("narita-masahiko", "成田 雅彦", "masahiko");
		SpgUser u91 = spgss.findUser("narita-masahiko");
		spgss.createUser("sakamori", "酒森 潔", "sakamori");
		SpgUser u92 = spgss.findUser("sakamori");
		spgss.createUser("*NOBODY", "未割り当て", "*none");
		SpgUser u99 = spgss.findUser("*NOBODY");

		// ユーザーをプロジェクトのメンバーに登録する（PBL0704)
		SpgMember m11 = spgss.addMember(p1.getId(), u1.getId(),	// 健さん
				SpgRole.PROJECTMANAGER);
		SpgMember m12 = spgss.addMember(p1.getId(), u2.getId(), // 信さん
				SpgRole.PROJECTMEMBER);
		SpgMember m13 = spgss.addMember(p1.getId(), u3.getId(), // 篠塚さん
				SpgRole.PROJECTMEMBER);
		SpgMember m14 = spgss.addMember(p1.getId(), u4.getId(), // 中谷さん
				SpgRole.PROJECTMEMBER);
		SpgMember m15 = spgss.addMember(p1.getId(), u5.getId(), // 山内さん
				SpgRole.PROJECTMEMBER);
		SpgMember m101 = spgss.addMember(p1.getId(), u90.getId(),
				SpgRole.TEACHER);
		SpgMember m102 = spgss.addMember(p1.getId(), u91.getId(),
				SpgRole.TEACHER);
		SpgMember m109 = spgss.addMember(p1.getId(), u99.getId(),
				SpgRole.PROJECTMEMBER);

		// ユーザーをプロジェクトのメンバーに登録する（PBL0709)
		SpgMember m21 = spgss.addMember(p2.getId(), u10.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m22 = spgss.addMember(p2.getId(), u11.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m23 = spgss.addMember(p2.getId(), u12.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m24 = spgss.addMember(p2.getId(), u13.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m25 = spgss.addMember(p2.getId(), u14.getId(),
				SpgRole.PROJECTMANAGER);
		SpgMember m29 = spgss.addMember(p2.getId(), u4.getId(),
				SpgRole.PROJECTMANAGER); // マルチプロジェクト対応の確認のため
		SpgMember m201 = spgss.addMember(p2.getId(), u92.getId(),
				SpgRole.TEACHER);
		SpgMember m202 = spgss.addMember(p2.getId(), u90.getId(),
				SpgRole.TEACHER);
		SpgMember m209 = spgss.addMember(p2.getId(), u99.getId(),
				SpgRole.PROJECTMEMBER);


		// プロジェクトのタスクを作成する。
		
		// 発表日は2/24ですね。
		Calendar cal1 = Calendar.getInstance();

		cal1.set(2008, 1, 13, 20, 0);
		Date projectStartTime = cal1.getTime();

		cal1.set(2008, 1, 24, 9, 0);
		Date demoTime = cal1.getTime();

		// A.SPGプロジェクトのタスクを作成する ************************************

		// 1. SPGシステムの作成
		SpgTaskTemplete stt1 = new SpgTaskTemplete();
		stt1.name = "SPGシステム";
		stt1.workingTime = 0;
		stt1.isStartTimeSpecifyedByUser = true;
		stt1.startTimePlanned = projectStartTime;
		stt1.assignment = SpgAssignStatus.ACCEPTED;
		stt1.deliverableMemo = "";

		stt1.projectId = p1.getId();
		stt1.memberId = m11.getId();
		stt1.parentTaskId = spgss.getRootTask(p1.getId()).getId();

		spgss.createTask(stt1);
		SpgTask t1 = spgss.findTask(p1.getId(), "01");
		spgss.updateTaskProgress(t1.getId(), SpgProgressStatus.STARTED);
		
		// 1.1 WBS機能
		SpgTaskTemplete stt11 = new SpgTaskTemplete();
		stt11.name = "WBS機能";
		stt11.workingTime = 0;
		stt11.isStartTimeSpecifyedByUser = true;
		stt11.startTimePlanned = projectStartTime;
		stt11.assignment = SpgAssignStatus.ACCEPTED;
		stt11.deliverableMemo = "";

		stt11.projectId = p1.getId();
		stt11.memberId = m12.getId();
		stt11.parentTaskId = t1.getId();

		spgss.createTask(stt11);
		SpgTask t11 = spgss.findTask(p1.getId(), "01.01");
		spgss.updateTaskProgress(t11.getId(), SpgProgressStatus.STARTED);
		spgss.updateTaskProgress(t11.getId(), SpgProgressStatus.FINISHED);

		
		// 1.1.1  WBS-設計
		SpgTaskTemplete stt111 = new SpgTaskTemplete();
		stt111.name = "WBS設計";
		stt111.workingTime = 8;
		stt111.isStartTimeSpecifyedByUser = true;
		stt111.startTimePlanned = projectStartTime;
		stt111.assignment = SpgAssignStatus.ACCEPTED;
		stt111.deliverableMemo = "";

		stt111.projectId = p1.getId();
		stt111.memberId = m12.getId();
		stt111.parentTaskId = t11.getId();
		spgss.createTask(stt111);
		SpgTask t111 = spgss.findTask(p1.getId(), "01.01.01");
		spgss.updateTaskProgress(t111.getId(), SpgProgressStatus.STARTED);
		spgss.updateTaskProgress(t111.getId(), SpgProgressStatus.FINISHED);

		
		// 1.1.2  WBS-実装
		SpgTaskTemplete stt112 = new SpgTaskTemplete();
		stt112.name = "WBS実装";
		stt112.workingTime = 16;
		stt112.isStartTimeSpecifyedByUser = true;
		cal1.set(2008, 1, 15, 20, 0);
		Date wbsImplStartTime = cal1.getTime();
		stt112.startTimePlanned = wbsImplStartTime;
		stt112.assignment = SpgAssignStatus.ACCEPTED;
		stt112.deliverableMemo = "";

		stt112.projectId = p1.getId();
		stt112.memberId = m12.getId();
		stt112.parentTaskId = t11.getId();
		stt112.PredecessorIds.add(t111.getId());
		spgss.createTask(stt112);
		SpgTask t112 = spgss.findTask(p1.getId(), "01.01.02");
		spgss.updateTaskProgress(t112.getId(), SpgProgressStatus.STARTED);
		spgss.updateTaskProgress(t112.getId(), SpgProgressStatus.FINISHED);

		
		// 1.2 ToDo機能
		SpgTaskTemplete stt12 = new SpgTaskTemplete();
		stt12.name = "ToDo機能";
		stt12.workingTime = 0;
		stt12.isStartTimeSpecifyedByUser = true;
		stt12.startTimePlanned = projectStartTime;
		stt12.assignment = SpgAssignStatus.ACCEPTED;
		stt12.deliverableMemo = "";

		stt12.projectId = p1.getId();
		stt12.memberId = m13.getId();
		stt12.parentTaskId = t1.getId();
		spgss.createTask(stt12);
		SpgTask t12 = spgss.findTask(p1.getId(), "01.02");
		spgss.updateTaskProgress(t12.getId(), SpgProgressStatus.STARTED);

		// 1.2.1  ToDo設計
		SpgTaskTemplete stt121 = new SpgTaskTemplete();
		stt121.name = "ToDo設計";
		stt121.workingTime = 4;
		stt121.isStartTimeSpecifyedByUser = true;
		stt121.startTimePlanned = projectStartTime;
		stt121.assignment = SpgAssignStatus.ACCEPTED;
		stt121.deliverableMemo = "";

		stt121.projectId = p1.getId();
		stt121.memberId = m13.getId();
		stt121.parentTaskId = t12.getId();
		spgss.createTask(stt121);
		SpgTask t121 = spgss.findTask(p1.getId(), "01.02.01");
		spgss.updateTaskProgress(t121.getId(), SpgProgressStatus.STARTED);

		// 1.2.2  ToDo実装
		SpgTaskTemplete stt122 = new SpgTaskTemplete();
		stt122.name = "ToDo実装";
		stt122.workingTime = 20;
		stt122.isStartTimeSpecifyedByUser = true;
		cal1.set(2008, 1, 14, 20, 0);
		Date todoImplStartTime = cal1.getTime();
		stt122.startTimePlanned = todoImplStartTime;
		stt122.assignment = SpgAssignStatus.ACCEPTED;
		stt122.deliverableMemo = "";

		stt122.projectId = p1.getId();
		stt122.memberId = m13.getId();
		stt122.parentTaskId = t12.getId();
		stt122.PredecessorIds.add(t121.getId());
		spgss.createTask(stt122);
		SpgTask t122 = spgss.findTask(p1.getId(), "01.02.02");
		spgss.updateTaskProgress(t122.getId(), SpgProgressStatus.STARTED);

		
		
		// 1.3 進捗表示機能
		SpgTaskTemplete stt13 = new SpgTaskTemplete();
		stt13.name = "進捗表示機能";
		stt13.workingTime = 1;
		stt13.isStartTimeSpecifyedByUser = true;
		stt13.startTimePlanned = projectStartTime;
		stt13.assignment = SpgAssignStatus.ACCEPTED;
		stt13.deliverableMemo = "";

		stt13.projectId = p1.getId();
		stt13.memberId = m15.getId();
		stt13.parentTaskId = t1.getId();
		spgss.createTask(stt13);
		SpgTask t13 = spgss.findTask(p1.getId(), "01.03");
		spgss.updateTaskProgress(t13.getId(), SpgProgressStatus.STARTED);
		spgss.updateTaskProgress(t13.getId(), SpgProgressStatus.FINISHED);

		
		// 1.3.1  進捗表示設計
		SpgTaskTemplete stt131 = new SpgTaskTemplete();
		stt131.name = "進捗表示設計";
		stt131.workingTime = 4;
		stt131.isStartTimeSpecifyedByUser = true;
		stt131.startTimePlanned = projectStartTime;
		stt131.assignment = SpgAssignStatus.ACCEPTED;
		stt131.deliverableMemo = "";

		stt131.projectId = p1.getId();
		stt131.memberId = m15.getId();
		stt131.parentTaskId = t13.getId();
		spgss.createTask(stt131);
		SpgTask t131 = spgss.findTask(p1.getId(), "01.03.01");
		spgss.updateTaskProgress(t131.getId(), SpgProgressStatus.STARTED);
		spgss.updateTaskProgress(t131.getId(), SpgProgressStatus.FINISHED);

		// 1.3.2  進捗表示実装
		SpgTaskTemplete stt132 = new SpgTaskTemplete();
		stt132.name = "進捗表示実装";
		stt132.workingTime = 8;
		stt132.isStartTimeSpecifyedByUser = true;
		cal1.set(2008, 1, 14, 20, 0);
		Date statusImplStartTime = cal1.getTime();
		stt132.startTimePlanned = statusImplStartTime;
		stt132.assignment = SpgAssignStatus.ACCEPTED;
		stt132.deliverableMemo = "";

		stt132.projectId = p1.getId();
		stt132.memberId = m15.getId();
		stt132.parentTaskId = t13.getId();
		stt132.PredecessorIds.add(t131.getId());
		spgss.createTask(stt132);
		SpgTask t132 = spgss.findTask(p1.getId(), "01.03.02");
		spgss.updateTaskProgress(t132.getId(), SpgProgressStatus.STARTED);
		spgss.updateTaskProgress(t132.getId(), SpgProgressStatus.FINISHED);

		
		// 1.4 統合
		SpgTaskTemplete stt14 = new SpgTaskTemplete();
		stt14.name = "統合";
		stt14.workingTime = 4;
		stt14.isStartTimeSpecifyedByUser = true;
		cal1.set(2008, 1, 19, 20, 0);
		Date integStartTime = cal1.getTime();
		stt14.startTimePlanned = integStartTime;
		stt14.assignment = SpgAssignStatus.REJECTED;
		stt14.deliverableMemo = "";

		stt14.projectId = p1.getId();
		stt14.memberId = m15.getId();
		stt14.parentTaskId = t1.getId();
		stt14.PredecessorIds.add(t112.getId());
		stt14.PredecessorIds.add(t122.getId());
		stt14.PredecessorIds.add(t132.getId());
		spgss.createTask(stt14);
		SpgTask t14 = spgss.findTask(p1.getId(), "01.04");
		
		
		// 2. SPGシステムのテスト
		SpgTaskTemplete stt2 = new SpgTaskTemplete();
		stt2.name = "テスト";
		stt2.workingTime = 12;
		stt2.isStartTimeSpecifyedByUser = true;

		cal1.set(2008, 1, 20, 20, 0);
		Date testStartTime = cal1.getTime();
		stt2.startTimePlanned = testStartTime;
		stt2.assignment = SpgAssignStatus.ASSIGNED;
		stt2.deliverableMemo = "";

		stt2.projectId = p1.getId();
		stt2.memberId = m14.getId();
		stt2.parentTaskId = spgss.getRootTask(p1.getId()).getId();
		stt2.PredecessorIds.add(t14.getId());	// 統合 -> テスト
		spgss.createTask(stt2);
		SpgTask t2 = spgss.findTask(p1.getId(), "02");

		
		// 3. SPGシステムの資料
		SpgTaskTemplete stt3 = new SpgTaskTemplete();
		stt3.name = "資料";
		stt3.workingTime = 16;
		stt3.isStartTimeSpecifyedByUser = true;

		cal1.set(2008, 1, 18, 20, 0);
		Date docStartTime = cal1.getTime();
		stt3.startTimePlanned = docStartTime;
		stt3.assignment = SpgAssignStatus.ASSIGNED;
		stt3.deliverableMemo = "";

		stt3.projectId = p1.getId();
		stt3.memberId = m11.getId();
		stt3.parentTaskId = spgss.getRootTask(p1.getId()).getId();

		spgss.createTask(stt3);
		SpgTask t3 = spgss.findTask(p1.getId(), "03");

		// 2. SPGシステムのデモ
		SpgTaskTemplete stt4 = new SpgTaskTemplete();
		stt4.name = "デモ";
		stt4.workingTime = 1;
		stt4.isStartTimeSpecifyedByUser = true;

		stt4.startTimePlanned = demoTime;
		stt4.assignment = SpgAssignStatus.CREATED;
		stt4.deliverableMemo = "";

		stt4.projectId = p1.getId();
		stt4.memberId = m14.getId();
		stt4.parentTaskId = spgss.getRootTask(p1.getId()).getId();
		stt4.PredecessorIds.add(t2.getId());	// テスト＋資料 -> デモ
		stt4.PredecessorIds.add(t3.getId());	

		spgss.createTask(stt4);
		SpgTask t4 = spgss.findTask(p1.getId(), "04");


		// B.PMOプロジェクトのタスクを作成する
		//（適当で勘弁）
	
		Calendar cal2 = Calendar.getInstance();
		cal2.set(2008, 1, 1, 12, 0);

		// 1. パネル
		SpgTaskTemplete stt_b1 = new SpgTaskTemplete();
		stt_b1.name = "パネル";
		stt_b1.workingTime = 0;
		stt_b1.isStartTimeSpecifyedByUser = true;
		stt_b1.startTimePlanned = cal2.getTime();
		stt_b1.assignment = SpgAssignStatus.ACCEPTED;
		stt_b1.deliverableMemo = "";

		stt_b1.projectId = p2.getId();
		stt_b1.memberId = m29.getId();
		stt_b1.parentTaskId = spgss.getRootTask(p2.getId()).getId();

		spgss.createTask(stt_b1);
		SpgTask b_t1 = spgss.findTask(p2.getId(), "01");
		spgss.updateTaskProgress(b_t1.getId(), SpgProgressStatus.STARTED);

		// 1.1 パネル作成依頼
		SpgTaskTemplete stt_b11 = new SpgTaskTemplete();
		stt_b11.name = "パネル作成依頼";
		stt_b11.workingTime = 68;
		stt_b11.isStartTimeSpecifyedByUser = true;
		stt_b11.startTimePlanned = cal2.getTime();
		stt_b11.assignment = SpgAssignStatus.ACCEPTED;
		stt_b11.deliverableMemo = "";

		stt_b11.projectId = p2.getId();
		stt_b11.memberId = m29.getId();
		stt_b11.parentTaskId = b_t1.getId();

		spgss.createTask(stt_b11);
		SpgTask b_t11 = spgss.findTask(p2.getId(), "01.01");

		// 1.1 パネル印刷
		SpgTaskTemplete stt_b12 = new SpgTaskTemplete();
		stt_b12.name = "パネル印刷";
		stt_b12.workingTime = 16;
		stt_b12.isStartTimeSpecifyedByUser = true;
		cal2.set(2008, 1, 18, 9, 0);
		stt_b12.startTimePlanned = projectStartTime;
		stt_b12.assignment = SpgAssignStatus.ASSIGNED;
		stt_b12.deliverableMemo = "";

		stt_b12.projectId = p2.getId();
		stt_b12.memberId = m29.getId();
		stt_b12.parentTaskId = b_t1.getId();

		spgss.createTask(stt_b12);
		SpgTask b_t12 = spgss.findTask(p2.getId(), "01.02");

		
		// C.個人プロジェクトのタスクを作成する
		//（適当で勘弁）
		
		SpgProject pp = spgss.findProject("a0633kn");
		Set<SpgMember> mmSet = pp.getMembers();	
		SpgMember[] mmArray = mmSet.toArray(new SpgMember[1]);

		Calendar cal3 = Calendar.getInstance();

		// 1. ミサに行く
		SpgTaskTemplete stt_c1 = new SpgTaskTemplete();
		stt_c1.name = "ミサに行く";
		stt_c1.workingTime = 2;
		stt_c1.isStartTimeSpecifyedByUser = true;
		cal3.set(2008, 1, 23, 8, 0);
		stt_c1.startTimePlanned = cal3.getTime();
		stt_c1.assignment = SpgAssignStatus.ACCEPTED;
		stt_c1.deliverableMemo = "";
		
		stt_c1.projectId = pp.getId();
		stt_c1.memberId = mmArray[0].getId();
		stt_c1.parentTaskId = spgss.getRootTask(pp.getId()).getId();

		spgss.createTask(stt_c1);
		SpgTask c_t1 = spgss.findTask(pp.getId(), "01");

		// 2. 参考書を買う
		SpgTaskTemplete stt_c2 = new SpgTaskTemplete();
		stt_c2.name = "参考書を買う";
		stt_c2.workingTime = 2;
		stt_c2.isStartTimeSpecifyedByUser = true;
		cal3.set(2008, 2, 2, 15, 0);
		stt_c2.startTimePlanned = cal3.getTime();
		stt_c2.assignment = SpgAssignStatus.ACCEPTED;
		stt_c2.deliverableMemo = "";
		
		stt_c2.projectId = pp.getId();
		stt_c2.memberId = mmArray[0].getId();
		stt_c2.parentTaskId = spgss.getRootTask(pp.getId()).getId();

		spgss.createTask(stt_c2);
		SpgTask c_t2 = spgss.findTask(pp.getId(), "02");
		spgss.updateTaskProgress(c_t2.getId(), SpgProgressStatus.STARTED);

		
		
	}

	public String print() {

		StringBuffer sbuf = new StringBuffer(2048);

		sbuf.append("*** registerd project : ");
		List<SpgProject> allproject = spDao.findAll();
		for (SpgProject sp : allproject) {
			sbuf.append(sp.getName() + " ");
		}

		sbuf.append("*** registered user : ");
		List<SpgUser> allUser = suDao.findAll();
		for (SpgUser su : allUser) {
			sbuf.append(su.getName() + " ");
		}

		sbuf.append("*** project->assigned member->user name : ");
		List<SpgProject> allproject2 = spDao.findAll();
		for (SpgProject sp : allproject2) {
			List<SpgMember> members = (List<SpgMember>) sp.getMembers();
			for (SpgMember sm : members) {
				sbuf.append(sm.getUser().getName() + " ");
			}
		}

		sbuf.append("*** task->assigned member -> user name : ");
		List<SpgTask> allTask = stDao.findAll();
		for (SpgTask st : allTask) {
			sbuf.append(st.getName() + " -> "
					+ st.getMember().getUser().getName() + " ");
		}

		sbuf.append("*** member->assigned task : ");
		List<SpgMember> allMember = smDao.findAll();
		for (SpgMember sm : allMember) {
			sbuf.append(sm.getUser().getName() + " ");
			List<SpgTask> memberTasks = (List<SpgTask>) sm.getTasks();
			for (SpgTask mt : memberTasks) {
				sbuf.append(mt.getName() + " ");
			}
		}

		sbuf.append("*** project->wbs->task : ");
		List<SpgProject> allproject3 = spDao.findAll();
		for (SpgProject sp : allproject3) {
			SpgWBS wbs = sp.getWbs();
			sbuf.append(" * wbs id : ");
			sbuf.append(wbs.getId());
			sbuf.append(" * ");
			List<SpgTask> tasks = (List<SpgTask>) wbs.getTasks();
			for (SpgTask st : tasks) {
				sbuf.append(st.getName() + " ");
			}
		}

		String result = sbuf.toString();
		return result;

	}

	public String print2() {

		StringBuffer sbuf = new StringBuffer(36);
		sbuf.append("all member : ");
		List<SpgMember> allMember = smDao.findAll();
		for (SpgMember sm : allMember) {
			sbuf.append(sm.getUser().getName() + " ");
		}
		String result = sbuf.toString();
		System.out.println(result);
		return result;

	}

	public String print3() {

		SpgTask t1 = stDao.find(1);
		SpgTask t2 = stDao.find(2);
		SpgTask t3 = stDao.find(3);
		if (t1.getChildren().size() == 0) {
			t2.setParent(t1);
			t3.setParent(t1);
		}

		StringBuffer sbuf = new StringBuffer(120);
		sbuf.append("this task name(task id 1): ");
		sbuf.append(t1.getName() + " ");
		sbuf.append(" * child tasks names: ");
		List<SpgTask> tchildrenl = new LinkedList<SpgTask>();
		tchildrenl.clear();
		tchildrenl = t1.getChildren();
		for (SpgTask st : tchildrenl) {
			sbuf.append(tchildrenl.indexOf(st) + " ");
			sbuf.append(st.getName() + " ");
		}
		sbuf.append("  * parent task of task id 2: ");
		sbuf.append(t2.getParent().getName());

		String result = sbuf.toString();
		System.out.println(result);
		return result;

	}

	public String print4() {

		StringBuffer sbuf = new StringBuffer(120);

		SpgAssignStatus assignstatus = SpgAssignStatus.ACCEPTED;

		/*
		 * Daoのメソッドのテスト SpgProject sp = spDao.find(1); // 決め打ち SpgWBS sw =
		 * sp.getWbs();
		 * 
		 * Set<SpgMember> lm = sp.getMembers(); SpgMember[] am = lm.toArray(new
		 * SpgMember[0]);
		 * 
		 * for (int n = 0 ; n < am.length ; n++) {
		 * sbuf.append(am[n].getUser().getName()); sbuf.append(" -> "); List<SpgTask>
		 * col = stDao.findByProjectAndMemberAndAssignedStatus(sw.getId(),
		 * am[n], assignstatus, "wbsNumber"); for (SpgTask st : col) {
		 * sbuf.append(st.getName()); } sbuf.append("\n"); }
		 */

		/*
		 * Daoのメソッドのテスト String name = "" ; try { SpgUser u =
		 * suDao.findByName(name); sbuf.append(u.getDescription()); } catch
		 * (javax.persistence.NoResultException e) { sbuf.append("not found!"); }
		 */

		// Daoのメソッドのテスト
		SpgUser su = suDao.find(1); // 決め打ち
		SpgToDo std = su.getTodo();

		/*
		 * Set<SpgTask> tset = st.getTasks(); SpgTask[] tarray =
		 * tset.toArray(new SpgTask[0]);
		 * 
		 * for (int n = 0 ; n < tarray.length ; n++) {
		 * sbuf.append(tarray[n].getName()); sbuf.append(" -> ");
		 */

		String[] order = { "startTimePlanned" };
		List<SpgTask> col = stDao.findByUserTasksAndAssignStatus(std.getId(),
				assignstatus, order);
		for (SpgTask st : col) {
			sbuf.append(st.getName());
		}

		/*
		 * sbuf.append("\n"); }
		 */

		String result = sbuf.toString();
		System.out.println(result);
		return result;

	}

	public String print5() {

		StringBuffer sbuf = new StringBuffer(120);

		/*
		 * メソッドのテスト Boolean OK = spgss.isValidUser("a0605ni", "nobu");
		 * sbuf.append(OK); sbuf.append(" : "); Boolean notOK =
		 * spgss.isValidUser("a0605ni", "babu"); sbuf.append(notOK);
		 * sbuf.append(" : "); Boolean notOK2 = spgss.isValidUser("a0605nii",
		 * "nobu"); sbuf.append(notOK2);
		 */

		// メソッドのテスト
		/*
		 * Boolean a1 = spgss.updateTaskProgress(1,
		 * SpgProgressStatus.UNTOUCHED); sbuf.append(a1); sbuf.append(" : ");
		 * Boolean a2 = spgss.updateTaskProgress(1, SpgProgressStatus.FINISHED);
		 * sbuf.append(a2); sbuf.append(" : "); Boolean a3 =
		 * spgss.updateTaskProgress(1, SpgProgressStatus.STARTED);
		 * sbuf.append(a3); sbuf.append(" : "); Boolean a4 =
		 * spgss.updateTaskProgress(1, SpgProgressStatus.UNTOUCHED);
		 * sbuf.append(a4); sbuf.append(" : "); Boolean a5 =
		 * spgss.updateTaskProgress(1, SpgProgressStatus.STARTED);
		 * sbuf.append(a5); sbuf.append(" : "); Boolean a6 =
		 * spgss.updateTaskProgress(1, SpgProgressStatus.FINISHED);
		 * sbuf.append(a6); sbuf.append(" : "); Boolean a7 =
		 * spgss.updateTaskProgress(1, SpgProgressStatus.UNTOUCHED);
		 * sbuf.append(a7); sbuf.append(" : "); Boolean a8 =
		 * spgss.updateTaskProgress(1, SpgProgressStatus.STARTED);
		 * sbuf.append(a7); sbuf.append(" : "); Boolean a9 =
		 * spgss.updateTaskProgress(1, SpgProgressStatus.FINISHED);
		 * sbuf.append(a9); sbuf.append(" : ");
		 */

		/*
		 * メソッドのテスト spgss.acceptTask(4);
		 */

		spgss.assignTask(1, 2);

		String result = sbuf.toString();
		System.out.println(result);
		return result;

	}

}
